package cn.edu.scau.cmi.xiaozecheng.adapter;

import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xiao
 * @date 2019/10/14/014 11:03 PM
 */
public class Controller {
    public TextField idInput;
    public TextField nameInput;
    public TextArea resultText;
    public TextField nameInput1;
    public TextField idInput1;
    public TextArea resultText1;

    private List<Student> list1 = new ArrayList<>();
    private List<Student> list2 = new ArrayList<>();
    private Integer getIdInput(){
        return Integer.parseInt(idInput.getText().trim());
    }
    private String getNameInput(){
        return nameInput.getText().trim();
    }
    private Integer getIdInput1(){
        return Integer.parseInt(idInput1.getText().trim());
    }
    private String getNameInput1(){
        return nameInput1.getText().trim();
    }
    public void clickButton(){
        list1.add(new Student(getIdInput(), getNameInput()) );
        //tableview.getItems().setAll(list);
        @SuppressWarnings("all")
        List<Student> result = new ClassAdapter().sortStudent(list1);
        resultText.clear();
        nameInput.clear();
        idInput.clear();
        for (Student s:result) {
            resultText.appendText(s.toString()+'\n');
        }
        resultText.setEditable(false);

    }
    public void clickButton2(){
        list2.add(new Student(getIdInput1(), getNameInput1()) );
        //tableview.getItems().setAll(list);
        @SuppressWarnings("all")
        List<Student> result = new ObjectAdapter().sortStudent(list2);
        resultText1.clear();
        nameInput1.clear();
        idInput1.clear();
        for (Student s:result) {
            resultText1.appendText(s.toString()+'\n');
        }
        resultText1.setEditable(false);
    }
}
